package com.example.ppapp;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.TextView;

import com.example.ppapp.activity.ShopActivity;
import com.example.ppapp.adapter.ItemListViewAdapter;
import com.example.ppapp.utils.ContentDatas;

import java.util.ArrayList;
import java.util.List;

public class MainActivity extends AppCompatActivity {
        private ListView listView;
        private List<String> dailyKindList;
        private ItemListViewAdapter adapter;

        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
            initView();
        }

        private void initView() {
            listView = findViewById(R.id.listView);
            TextView tv_title = findViewById(R.id.tv_title);
            tv_title.setText("日常用品");
            dailyKindList = new ArrayList<>(ContentDatas.dailyKindList);
            adapter = new ItemListViewAdapter(this, dailyKindList);
            listView.setAdapter(adapter);
            listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
                @Override
                public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                    startActivity(new Intent(MainActivity.this, ShopActivity.class)
                            .putExtra("id", position)
                            .putExtra("title", dailyKindList.get(position)));
                }
            });
        }
    }
